package com.bryantkobe.myspringcode.controller;

import com.bryantkobe.myspringcode.utils.RSAUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.KeyPair;

/**
 * @description: 初始controller
 * @author: alienwarezzl
 * @date: 2025/3/30
 */
@RestController
@RequestMapping("/hello")
@Tag(name = "初始模块",description = "初始模块描述")
public class HelloWorldController {

    @Operation(summary = "HelloWorld",description = "你好世界!")
    @GetMapping("/world")
    @SecurityRequirement(name = "Authorization")
    public String helloWorld() throws Exception {
        KeyPair keyPair = RSAUtils.generateKeyPair();
        String publicKey = RSAUtils.getPublicKeyString(keyPair.getPublic());
        String privateKey = RSAUtils.getPrivateKeyString(keyPair.getPrivate());

        System.out.println("撒大苏打撒旦撒旦");

        System.out.println("公钥: " + publicKey);
        System.out.println("私钥: " + privateKey);

        // 加密测试
        String originalText = "Hello, RSA加密测试!";
        System.out.println("原始文本: " + originalText);

        String encryptedText = RSAUtils.encrypt(originalText, publicKey);
        System.out.println("加密后: " + encryptedText);

        // 解密测试
        String decryptedText = RSAUtils.decrypt(encryptedText, privateKey);
        System.out.println("解密后: " + decryptedText);
        System.out.println("的似的是的");
        return "Hello World";
    }
}
